package com.pureut.quality.controller;

import com.pureut.common.core.web.controller.BaseController;
import com.pureut.common.core.web.domain.AjaxResult;
import com.pureut.common.core.web.page.TableDataInfo;
import com.pureut.common.log.annotation.Log;
import com.pureut.common.log.enums.BusinessType;
import com.pureut.common.security.annotation.RequiresPermissions;
import com.pureut.quality.domain.dto.QualityInventoryRecheckDto;
import com.pureut.quality.domain.vo.QualityInventoryRecheckVo;
import com.pureut.quality.service.QualityInventoryRecheckService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/***
 * 库存复检控制层
 * Author:C
 * Date:2023/02/09 11:38
 * @DESC
 */
@RestController
@RequestMapping("/quality-inventory-recheck")
public class QualityInventoryRecheckController extends BaseController {

    @Resource
    QualityInventoryRecheckService qualityInventoryRecheckService;

    /**
     * 库存复检列表
     */
    @RequiresPermissions("quality:inspecmanage:reinspect:list")
    @GetMapping("/list")
    public TableDataInfo getList(QualityInventoryRecheckVo qualityInventoryRecheckVo) {
        startPage();
        //查询库存复检列表
        List<QualityInventoryRecheckDto> list = qualityInventoryRecheckService.getRecheckList(qualityInventoryRecheckVo);
        return getDataTable(list);
    }

    /**
     * 库存复检新增
     */
    @RequiresPermissions("quality:inspecmanage:reinspect:add")
    @PostMapping("/add")
    @Log(title = "库存复检新增", businessType = BusinessType.INSERT)
    public AjaxResult add(@Validated @RequestBody QualityInventoryRecheckVo qualityInventoryRecheckVo) throws Exception {
        return toAjax(qualityInventoryRecheckService.add(qualityInventoryRecheckVo));
    }

    /**
     * 撤销
     */
    @RequiresPermissions("quality:inspecmanage:reinspect:revoke")
    @GetMapping("/revoke/{ids}")
    @Log(title = "库存复检撤销", businessType = BusinessType.UPDATE)
    public AjaxResult revoke(@PathVariable("ids") String ids) {
        return toAjax(qualityInventoryRecheckService.revoke(ids));
    }

    /**
     * 查看
     */
    @RequiresPermissions("quality:inspecmanage:reinspect:query")
    @GetMapping("/view/{id}")
    public AjaxResult getView(@PathVariable("id") Long id) {
        return AjaxResult.success(qualityInventoryRecheckService.getView(id));
    }
}
